#include "register.h"
#include "adata.h"

using namespace reg;

Register::Register():
        head_ (new Record)

{
    head_->type = FIRST;
}

Register::~Register(){
    mutex_.lock();
    for(Record * r = head_; r!=NULL; ) {
        Record * tmp = r->next;
        delete r;
        r = tmp;
    }
    mutex_.unlock();
}

const reg::Id Register::insert(const AData& data, Gl::TicksTime time, const AData* parent){
    if (time < 0) return NULL;
    mutex_.lock();
        //Type t = data.type();
        //Record r = findLeft(Gl::TicksTime time);
    mutex_.unlock();
}
void Register::read (const Id id,  AData* data_out, Gl::TicksTime time_out, AData* parent_out, Type type_out) const{

}
const QList <reg::Id> & Register::children (const Id id) const {

}
bool Register::remove(Id id){
    mutex_.lock();
    mutex_.unlock();
}
bool Register::move(Id id, Gl::TicksTime){
    mutex_.lock();
    mutex_.unlock();
}

Register::Record::Record() :
        data(NULL),
        time(0),
        parent(NULL),
        type(NONE),
        children(),
        prev(NULL),
        next(NULL)
{
}

Register::Record::~Record(){
    delete data;
    if (!parent) parent->children.removeAll(this);
    foreach(Record * r, children) r->parent = 0;
}
